package com.ruoyi.produce.process.planoutsource.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.produce.process.planoutsource.domain.ProducePlanOutsource;
import com.ruoyi.produce.process.planoutsource.domain.ProducePlanOutsourceCond;
import com.ruoyi.produce.process.planoutsource.service.IProducePlanOutsourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 委外生产计划信息
 *
 * @author Drj 2021/6/28
 */
@RestController
@RequestMapping("/produce/planoutsource")
@Api(value = "委外生产计划信息模块", tags = "委外生产计划信息接口")
public class ProducePlanOutsourceController extends BaseController {
    @Autowired
    private IProducePlanOutsourceService producePlanOutsourceService;
    /**
     * 获取委外生产计划
     * @param cond
     * @return
     */
    @ApiOperationSupport(includeParameters = {"ProducePlanOutsource.produceId", "ProducePlanOutsource.planOutsourceId", "ProducePlanOutsource.saleOrderId", "ProducePlanOutsource.supplierInfoId", "ProducePlanOutsource.createTime"})
    @ApiOperation(value = "获取委外生产计划列表",notes = "查询所有委外生产计划信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody ProducePlanOutsourceCond cond){
        startPage();
        List<ProducePlanOutsource> producePlanOutsourceList = producePlanOutsourceService.selectProducePlanOutsourceList(cond);
        return getDataTable(producePlanOutsourceList);
    }

    /**
     * 导出自委外生产计划
     * @param cond
     * @return
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody ProducePlanOutsourceCond cond)
    {
        List<ProducePlanOutsource> producePlanOutsourceList = producePlanOutsourceService.selectProducePlanOutsourceList(cond);
        ExcelUtil<ProducePlanOutsource> util = new ExcelUtil<ProducePlanOutsource>(ProducePlanOutsource.class);
        return util.exportExcel(producePlanOutsourceList, "委外生产计划数据");
    }

    /**
     * 新增自委外生产计划
     * @param producePlanOutsource
     * @return
     */
    @ApiOperation(value = "新增自委外生产计划", notes = "新增自委外生产计划")
    @ApiImplicitParam(name = "producePlanOutsource", value = "新增自委外生产计划", dataType = "ProducePlanOutsource")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ProducePlanOutsource producePlanOutsource){
        return toAjax(producePlanOutsourceService.insertProducePlanOutsource(producePlanOutsource));
    }

    /**
     * 修改委外生产计划
     * @param producePlanOutsource
     * @return
     */
    @ApiOperation(value = "修改委外生产计划", notes = "修改委外生产计划")
    @ApiImplicitParam(name = "producePlanOutsource", value = "修改委外生产计划", dataType = "ProducePlanOutsource")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody ProducePlanOutsource producePlanOutsource)
    {
        return toAjax(producePlanOutsourceService.updateProducePlanOutsource(producePlanOutsource));
    }

    /**
     * 删除委外生产计划
     * 仅修改删除标志位
     * @param producePlanOutsource
     * @return
     */
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody ProducePlanOutsource producePlanOutsource)
    {

        return toAjax(producePlanOutsourceService.updateProducePlanOutsourceDeleteFlag(producePlanOutsource));
    }
}
